<template>
	<view class="tab-bar">
		<view class="tab-bar-border"></view>
		<view v-for="(item, index) in list" :key="index" class="tab-bar-item" @click="switchTab(item)">
			<view class="tab-bar-item-content">
				<text class="iconfont" :class="[item.iconClass, selected === item.pagePath ? 'active' : '']"></text>
				<text class="tab-text" :class="{ 'active': selected === item.pagePath }">{{ item.text }}</text>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		props: {
			selected: {
				type: String,
				default: ''
			}
		},
		data() {
			return {
				color: "#7A7E83",
				selectedColor: "#3cc51f",
				list: [{
					pagePath: "/pages/home/index",
					iconClass: "icon-home",
					text: "首页"
				}, {
					pagePath: "/pages/order/list",
					iconClass: "icon-dingdan",
					text: "订单"
				}]
			};
		},
		methods: {
			switchTab(item) {
				const url = item.pagePath
				uni.switchTab({
					url
				})
			}
		}
	}
</script>

<style scoped>
	.tab-bar {
		position: fixed;
		bottom: 0;
		left: 0;
		right: 0;
		height: calc(50px + env(safe-area-inset-bottom));
		background: #ffffff;
		padding-top: 10px;
		display: flex;
		flex-direction: row;
		padding-bottom: env(safe-area-inset-bottom); /*适配iPhone X等机型*/
		box-sizing: border-box;
	}

	.tab-bar-border {
		background-color: rgba(0, 0, 0, 0.1);
		position: absolute;
		left: 0;
		top: 0;
		width: 100%;
		height: 1px;
		transform: scaleY(0.5);
	}

	.tab-bar-item {
		flex: 1;
		text-align: center;
		display: flex;
		justify-content: center;
		align-items: center;
	}

	.tab-bar-item-content {
		display: flex;
		flex-direction: column;
		align-items: center;
	}

	.iconfont {
		font-size: 24px;
		color: #7A7E83;
		margin-bottom: 3px;
	}

	.tab-text {
		font-size: 11px;
		color: #7A7E83;
	}

	.iconfont.active, .tab-text.active {
		color: #3cc51f; /* selectedColor */
	}
</style>
